SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Friend]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Friend](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[HostUserId] [int] NOT NULL,
	[HostUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[FriendUserId] [int] NOT NULL,
	[FriendUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[State] [int] NOT NULL CONSTRAINT [DF_FriendInvite_State]  DEFAULT ((0)),
	[PostTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
	CONSTRAINT [PK_FriendInvite] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Comment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Comment](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[HostUserId] [int] NOT NULL,
	[Body] [ntext] COLLATE Chinese_PRC_CI_AS NOT NULL,
	[FloorNo] [int] NOT NULL CONSTRAINT [DF_Comment_FloorNo]  DEFAULT ((0)),
	[ReplyFloorNo] [int] NOT NULL CONSTRAINT [DF_Comment_ReplyFloorNo]  DEFAULT ((0)),
	[PostUserId] [int] NOT NULL,
	[PostUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[Ip] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[PostTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
	[IsRead] [int] NOT NULL CONSTRAINT [DF_Comment_IsRead]  DEFAULT ((0)),
	CONSTRAINT [PK_Comment] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Action]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Action](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[FromUserId] [int] NOT NULL,
	[FromUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[ToUserId] [int] NOT NULL,
	[ToUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[ActionType] [int] NOT NULL,
	[Remark] [nvarchar](2000) COLLATE Chinese_PRC_CI_AS NULL,
	[PostTime] [datetime] NOT NULL,
	[IsRead] [int] NOT NULL CONSTRAINT [DF_Action_IsRead]  DEFAULT ((0)),
	CONSTRAINT [PK_Action] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LogTopic]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LogTopic](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Type] [int] NOT NULL CONSTRAINT [DF_LogTopic_Type]  DEFAULT ((0)),
	[HostUserId] [int] NOT NULL,
	[Title] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[Body] [ntext] COLLATE Chinese_PRC_CI_AS NOT NULL,
	[PostTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
	[LatestReplyUserId] [int] NULL,
	[LatestReplyUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[LatestReplyTime] [datetime] NULL,
	[ReplyCount] [int] NOT NULL CONSTRAINT [DF_LogTopic_ReplyCount]  DEFAULT ((0)),
	[Hits] [int] NOT NULL CONSTRAINT [DF_LogTopic_Hits]  DEFAULT ((0)),
	[IsTop] [int] NOT NULL CONSTRAINT [DF_LogTopic_IsTop]  DEFAULT ((0)),
 CONSTRAINT [PK_LogTopic] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LogReply]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[LogReply](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[LogTopicId] [int] NOT NULL,
	[Body] [ntext] COLLATE Chinese_PRC_CI_AS NOT NULL,
	[FloorNo] [int] NOT NULL CONSTRAINT [DF_LogReply_FloorNo]  DEFAULT ((0)),
	[ReplyFloorNo] [int] NOT NULL CONSTRAINT [DF_LogReply_ReplyFloorNo]  DEFAULT ((0)),
	[PostUserId] [int] NOT NULL,
	[PostUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[Ip] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[PostTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
	CONSTRAINT [PK_LogReply] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UserActivity]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[UserActivity](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[ActivityId] [int] NOT NULL,
	[UserId] [int] NOT NULL,
	[UserName] [nvarchar](50) NOT NULL,
	[Message] [nvarchar](2000) NOT NULL,
	[Connactinfo] [nvarchar](100) NULL,
	[IsVerify] [int] NOT NULL CONSTRAINT [DF_UserActivity_IsVerify]  DEFAULT ((0)),
	[ApplyDate] [datetime] NOT NULL,
	[Reply] [nvarchar](2000) NULL,
	[ReplyDate] [datetime] NULL,
 CONSTRAINT [PK_UserActivity] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[textinfotype]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[textinfotype](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[parentid] [int] NOT NULL CONSTRAINT [DF_textinfotype_parentid]  DEFAULT ((0)),
	[typename] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_textinfotype] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[patientrelation]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[patientrelation](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[hostusername] [nvarchar](50) NOT NULL,
	[clientusername] [nvarchar](50) NOT NULL,
	[relation] [int] NOT NULL,
 CONSTRAINT [PK_patientrelation] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[loginfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[loginfo](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[loginip] [nvarchar](20) NOT NULL,
	[loginusername] [nvarchar](50) NOT NULL,
	[logindate] [datetime] NOT NULL,
 CONSTRAINT [PK_loginfo] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[image]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[image](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[imagepath] [nvarchar](200) NOT NULL,
 CONSTRAINT [PK_image] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[district]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[district](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[parentid] [int] NOT NULL CONSTRAINT [DF_district_parentid]  DEFAULT ((0)),
	[districtname] [nvarchar](50) NOT NULL,
	[ordervalue] [int] NULL DEFAULT ((0)),
 CONSTRAINT [PK_district_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[message]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[message](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[msgfrom] [nvarchar](50) NOT NULL,
	[msgfromid] [int] NOT NULL,
	[msgto] [nvarchar](50) NOT NULL,
	[msgtoid] [int] NOT NULL,
	[folder] [smallint] NOT NULL,
	[new] [int] NOT NULL,
	[subject] [nvarchar](60) NOT NULL,
	[postdatetime] [datetime] NOT NULL,
	[message] [ntext] NOT NULL,
 CONSTRAINT [PK_message_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[diseasetype]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[diseasetype](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[parentid] [int] NOT NULL CONSTRAINT [DF_diseasetype_parentid]  DEFAULT ((0)),
	[diseasetypename] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_diseasetype_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[symptomtype]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[symptomtype](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[parentid] [int] NOT NULL CONSTRAINT [DF_symptomtype_parentid]  DEFAULT ((0)),
	[symptomtypename] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_symptomtype_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Group]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Group](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GroupName] [nvarchar](50) NOT NULL,
	[GroupType] [int] NOT NULL CONSTRAINT [DF_groupinfo_grouptype]  DEFAULT ((0)),
	[GroupTypeName] [nvarchar](50) NULL,
	[DiseaseId] [int] NOT NULL CONSTRAINT [DF_groupinfo_diseaseid]  DEFAULT ((0)),
	[TreatmentId] [int] NOT NULL CONSTRAINT [DF_groupinfo_treatmentid]  DEFAULT ((0)),
	[SymptomId] [int] NOT NULL CONSTRAINT [DF_groupinfo_symptomid]  DEFAULT ((0)),
	[LabcheckId] [int] NULL CONSTRAINT [DF_groupinfo_labcheckid]  DEFAULT ((0)),
	[Area] [nvarchar](50) NULL,
	[ProvinceId] [int] NOT NULL CONSTRAINT [DF_groupinfo_provinceid]  DEFAULT ((0)),
	[CityId] [int] NOT NULL CONSTRAINT [DF_groupinfo_cityid]  DEFAULT ((0)),
	[ProvinceName] [nvarchar](50) NULL,
	[CityName] [nvarchar](50) NULL,
	[Keyword] [nvarchar](500) NULL,
	[Introduction] [nvarchar](max) NULL,
	[Logo] [nvarchar](255) NULL,
	[Moderators] [nvarchar](500) NOT NULL,
	[AppUserId] [int] NULL,
	[AppUserName] [nvarchar](50) NULL,
	[UserNum] [int] NOT NULL CONSTRAINT [DF_groupinfo_usernum]  DEFAULT ((0)),
	[TopicNum] [int] NOT NULL CONSTRAINT [DF_groupinfo_topicnum]  DEFAULT ((0)),
	[ReplyNum] [int] NULL CONSTRAINT [DF_Group_ReplyNum]  DEFAULT ((0)),
	[PostNum] [int] NOT NULL CONSTRAINT [DF_groupinfo_postnum]  DEFAULT ((0)),
	[LimitUser] [int] NOT NULL CONSTRAINT [DF_groupinfo_limituser]  DEFAULT ((100)),
	[LastTopicId] [int] NULL CONSTRAINT [DF_Group_LastTopicId]  DEFAULT ((0)),
	[LastTopicTitle] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
	[LastPostUser] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[LastPostTime] [datetime] NULL,
	[IsGoodGroup] [int] NOT NULL CONSTRAINT [DF_groupinfo_isgoodgroup]  DEFAULT ((0)),
	[Hits] [int] NOT NULL CONSTRAINT [DF_groupinfo_hits]  DEFAULT ((0)),
	[CreatTime] [datetime] NOT NULL,
	[BrowserPermission] [int] NOT NULL,
	[JoinPermission] [int] NOT NULL,
    [IsValid] [int] NOT NULL CONSTRAINT [DF_Group_IsValid]  DEFAULT ((1)),
 CONSTRAINT [PK_groupinfo] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupInvite]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GroupInvite](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GroupId] [int] NOT NULL,
	[PostUserId] [int] NOT NULL,
	[PostUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[PostTime] [datetime] NOT NULL,
    [ReceiveUserId] [int] NOT NULL,
    [IsView] [int] NULL CONSTRAINT [DF_GroupInvite_IsView] DEFAULT ((0))
	CONSTRAINT [PK_GroupInvite] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[VisitRecord]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[VisitRecord](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[HostUserId] [int] NOT NULL,
	[VisitUserId] [int] NOT NULL,
	[VisitUserName] [nvarchar](100) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[VisitTime] [datetime] NOT NULL,
	CONSTRAINT [PK_VisitRecord] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[labcheck]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[labcheck](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[indicatorname] [nvarchar](50) NOT NULL,
	[introduction] [nvarchar](4000) NULL,
	[description] [nvarchar](max) NULL,
	[isquantified] [int] NOT NULL CONSTRAINT [DF_labcheck_isquantified]  DEFAULT ((0)),
	[measurementunits] [nvarchar](50) NULL,
	[choicesdescription] [nvarchar](2000) NULL,
	[limitvalues] [nvarchar](50) NULL,
	[normalvalues] [nvarchar](50) NULL,
	[updatetime] [datetime] NOT NULL,
	[gridvalues] [nvarchar](2000) NULL,
	[shortname] [nvarchar](50) NULL
 CONSTRAINT [PK_labcheck] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[treatmenttype]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[treatmenttype](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[parentid] [int] NOT NULL CONSTRAINT [DF_treatmenttype_parentid]  DEFAULT ((0)),
	[treatmenttypename] [nvarchar](50) NOT NULL,
 CONSTRAINT [PK_treatmentype_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupUser]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GroupUser](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GroupId] [int] NOT NULL,
	[UserId] [int] NOT NULL,
	[UserName] [nvarchar](50) NOT NULL,
	[Role] [int] NOT NULL,
	[TopicCount] [int] NOT NULL CONSTRAINT [DF_GroupUser_TopicCount]  DEFAULT ((0)),
	[ReplyCount] [int] NOT NULL CONSTRAINT [DF_GroupUser_ReplyCount]  DEFAULT ((0)),
	[PostCount] [int] NOT NULL CONSTRAINT [DF_GroupUser_PostCount]  DEFAULT ((0)),
	[JoinTime] [datetime] NOT NULL,
 CONSTRAINT [PK_groupusers] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Topic]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Topic](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Groupid] [int] NOT NULL,
	[Title] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[Body] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[PostUserId] [int] NOT NULL,
	[PostUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[PostTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NOT NULL,
	[LatestReplyUserId] [int] NULL,
	[LatestReplyUserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[LatestReplyTime] [datetime] NULL,
	[LatestReplyId] [int] NULL,
	[ReplyCount] [int] NOT NULL CONSTRAINT [DF_Topic_ReplyCount]  DEFAULT ((0)),
	[Hits] [int] NOT NULL CONSTRAINT [DF_GroupTopics_Hits]  DEFAULT ((0)),
	[IsBest] [int] NOT NULL CONSTRAINT [DF_GroupTopics_IsBest]  DEFAULT ((0)),
	[IsTop] [int] NOT NULL CONSTRAINT [DF_GroupTopics_IsTop]  DEFAULT ((0)),
	[IsGoodPost] [int] NOT NULL CONSTRAINT [DF_GroupTopics_IsGoodPost]  DEFAULT ((0)),
	[ShowLevel] [int] NOT NULL CONSTRAINT [DF_GroupTopics_ShowLevel]  DEFAULT ((0)),
	CONSTRAINT [PK_Topic] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupType]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GroupType](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GroupTypeName] [nvarchar](50) NOT NULL,
	[DiseaseType] [int] NOT NULL,
	[Introduction] [nvarchar](max) NULL,
	[Logo] [nvarchar](255) NULL,
	[GroupNum] [int] NOT NULL CONSTRAINT [DF_grouptype_groupnum]  DEFAULT ((0)),
 CONSTRAINT [PK_grouptype] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DiseaseGraphSetting]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[DiseaseGraphSetting](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[DiseaseId] [int] NOT NULL,
	[GraphGeneralRule] [nvarchar](max) NOT NULL,
	[GraphLabcheckRule] [nvarchar](max) NOT NULL,
	[GraphSymptomRule] [nvarchar](max) NOT NULL,
	[GraphTreatmentRule] [nvarchar](max) NOT NULL,
 CONSTRAINT [PK_DiseaseGraphSetting] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ActivityNews]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ActivityNews](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[Title] [nvarchar](255) NOT NULL,
	[Introduction] [nvarchar](4000) NULL,
	[Body] [nvarchar](max) NOT NULL,
	[StartTime] [datetime] NOT NULL,
	[EndTime] [datetime] NOT NULL,
	[area] [nvarchar](255) NULL,
	[Dimensions] [nvarchar](255) NOT NULL CONSTRAINT [DF_ActivityNews_Dimensions]  DEFAULT ((0)),
	[HasImage] [int] NOT NULL CONSTRAINT [DF_ActivityNews_HasImage]  DEFAULT ((0)),
	[ImagePath] [nvarchar](255) NULL,
	[Keyword] [nvarchar](50) NULL,
	[Source] [nvarchar](50) NULL,
	[UpdateTime] [datetime] NOT NULL,
 CONSTRAINT [PK_ActivityNews] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Reply]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[Reply](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[TopicId] [int] NOT NULL,
	[Body] [nvarchar](max) NOT NULL,
	[FloorNo] [int] NOT NULL CONSTRAINT [DF_Reply_FloorNo]  DEFAULT ((0)),
	[ReplyFloorNo] [int] NOT NULL CONSTRAINT [DF_Reply_ReplyFloorNo]  DEFAULT ((0)),
	[PostUserid] [int] NOT NULL,
	[PostUserName] [nvarchar](50) NOT NULL,
	[Ip] [nvarchar](50) NULL,
	[PostTime] [datetime] NOT NULL,
	[UpdateTime] [datetime] NULL,
	[GroupId] [int] NULL CONSTRAINT [DF_Reply_GroupId]  DEFAULT ((0)),
	[IsDel] [int] NULL CONSTRAINT [DF_Reply_IsDel] DEFAULT ((0))
 CONSTRAINT [PK_TopicReply] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GroupNews]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GroupNews](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[GroupId] [int] NOT NULL,
	[Title] [nvarchar](255) NOT NULL,
	[Introduction] [nvarchar](2000) NULL,
	[LinkUrl] [nvarchar](500) NULL,
	[Body] [nvarchar](max) NULL,
	[UpdateTime] [datetime] NOT NULL,
	[Source] [nvarchar](50) NULL,
 CONSTRAINT [PK_groupnews] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[textinfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[textinfo](
	[id] [int] NOT NULL,
	[typeid] [int] NOT NULL,
	[title] [nvarchar](200) NOT NULL,
	[txtcontent] [nvarchar](max) NULL,
	[source] [nvarchar](50) NULL,
	[uploaddate] [datetime] NOT NULL,
 CONSTRAINT [PK_textinfo] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AdminInfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AdminInfo](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[Password] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
 CONSTRAINT [PK_AdminInfo] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[userinfo](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UserTypeid] [int] NOT NULL,
	[UserTypeName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[UserName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[Email] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[Password] [nvarchar](32) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[PasswordBak] [nvarchar](32) COLLATE Chinese_PRC_CI_AS NULL,
	[ProvinceId] [int] NOT NULL CONSTRAINT [DF_user_provinceid]  DEFAULT ((0)),
	[CityId] [int] NOT NULL CONSTRAINT [DF_user_cityid]  DEFAULT ((0)),
	[Address] [nvarchar](100) COLLATE Chinese_PRC_CI_AS NULL,
	[ZipCode] [nvarchar](10) COLLATE Chinese_PRC_CI_AS NULL,
	[Birthday] [datetime] NULL,
	[Gender] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Avatar] [nvarchar](256) COLLATE Chinese_PRC_CI_AS NULL,
	[AvatarType] [int] NULL,
	[RegisteredDate] [datetime] NOT NULL,
	[Privacy] [int] NOT NULL CONSTRAINT [DF_user_privacy]  DEFAULT ((0)),
	[Telephone] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[MobilePhone] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Description] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
	[GroupIds] [nvarchar](200) COLLATE Chinese_PRC_CI_AS NULL,
	[IsActive] [tinyint] NOT NULL CONSTRAINT [DF_userinfo_isactive]  DEFAULT ((0)),
	[ActiveCode] [nvarchar](32) COLLATE Chinese_PRC_CI_AS NULL,
	[IsOnline] [tinyint] NOT NULL CONSTRAINT [DF_userinfo_isonline]  DEFAULT ((0)),
	[LastActivityDate] [datetime] NULL,
	[LastUpdateDate] [datetime] NULL,
	[LoginTime] [int] NOT NULL CONSTRAINT [DF_userinfo_logintime]  DEFAULT ((0)),
	[Interests] [nvarchar](200) COLLATE Chinese_PRC_CI_AS NULL,
	[ViewCount] [int] NOT NULL CONSTRAINT [DF_userinfo_ViewCount]  DEFAULT ((0)),
	[Height] [float] NULL CONSTRAINT [DF_userinfo_Height]  DEFAULT ((0)),
	[MSN] [nvarchar](100) COLLATE Chinese_PRC_CI_AS NULL,
	[QQ] [nvarchar](50) NULL
	CONSTRAINT [PK_userinfo_id] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tmpdisease]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tmpdisease](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[diseasename] [nvarchar](50) NOT NULL,
	[introduction] [nvarchar](4000) NOT NULL,
	[discription] [nvarchar](max) NOT NULL,
	[diseasetypeid] [int] NOT NULL,
	[firstsymbolofname] [nvarchar](50) NOT NULL,
	[uploaddate] [datetime] NOT NULL,
	[isvalid] [tinyint] NOT NULL CONSTRAINT [DF_tmpdisease_isvalid]  DEFAULT ((0)),
	[userid] [int] NOT NULL,
	CONSTRAINT [PK_tmpdisease_id] PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[disease](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[DiseaseName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[Introduction] [nvarchar](4000) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[description] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[diseasetypeid] [int] NOT NULL,
	[firstsymbolofname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[uploaddate] [datetime] NOT NULL,
	[ClassPatientId] [int] NOT NULL CONSTRAINT [DF_disease_ClassPatientId]  DEFAULT ((0)),
	[ClassPatientName] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL,
	[PatientCount] [int] NOT NULL CONSTRAINT [DF_disease_PatientCount]  DEFAULT ((0)),
	CONSTRAINT [PK_disease_id] PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tmpsymptom]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tmpsymptom](
	[id] [int] NOT NULL,
	[symptomname] [nvarchar](50) NOT NULL,
	[introduction] [nvarchar](4000) NOT NULL,
	[discription] [nvarchar](max) NOT NULL,
	[symptomtypeid] [int] NOT NULL CONSTRAINT [DF_tmpsymptom_symptomtypeid]  DEFAULT ((0)),
	[firstsymbolofname] [nvarchar](50) NOT NULL,
	[uploaddate] [datetime] NOT NULL,
	[isvalid] [tinyint] NOT NULL CONSTRAINT [DF_tmpsymptom_isvalid]  DEFAULT ((0)),
	[userid] [int] NOT NULL,
	[milddescription] [nvarchar](50) NULL,
	[moderatedescription] [nvarchar](50) NULL,
	[severedescription] [nvarchar](50) NULL,
 CONSTRAINT [PK_tmpsymptom_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[symptom]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[symptom](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[symptomname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[introduction] [nvarchar](4000) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[description] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[symptomtypeid] [int] NOT NULL CONSTRAINT [DF_symptom_symptomtypeid]  DEFAULT ((0)),
	[firstsymbolofname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[uploaddate] [datetime] NOT NULL,
	[milddescription] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[moderatedescription] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[severedescription] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[ClassPatientId] [int] NOT NULL CONSTRAINT [DF_symptom_ClassPatientId]  DEFAULT ((0)),
	[PatientCount] [int] NOT NULL CONSTRAINT [DF_symptom_PatientCount]  DEFAULT ((0)),
	[ClassDiseaseId] [int] NULL,
    [ClassPatientName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	CONSTRAINT [PK_symptom] PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[treatment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[treatment](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[treatmentname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[introduction] [nvarchar](4000) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[description] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[treatmenttypeid] [int] NOT NULL,
	[firstsymbolofname] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[uploaddate] [datetime] NOT NULL,
	[isquantified] [int] NOT NULL,
	[measurementunits] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[choicesdescription] [nvarchar](2000) COLLATE Chinese_PRC_CI_AS NULL,
	[limitvalues] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[ClassPatientId] [int] NOT NULL CONSTRAINT [DF_treatment_ClassPatientId]  DEFAULT ((0)),
	[PatientCount] [int] NOT NULL CONSTRAINT [DF_treatment_PatientCount]  DEFAULT ((0)),
	[GeneralName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[Merchant] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
    [ClassPatientName] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[frequency] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	CONSTRAINT [PK_treatment_id] PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tmptreatment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tmptreatment](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[treatmentname] [nvarchar](50) NOT NULL,
	[introduction] [nvarchar](4000) NOT NULL,
	[description] [nvarchar](max) NOT NULL,
	[treatmenttypeid] [int] NOT NULL CONSTRAINT [DF_tmptreatment_treatmenttypeid]  DEFAULT ((0)),
	[firstsymbolofname] [nvarchar](50) NOT NULL,
	[uploaddate] [datetime] NOT NULL,
	[isvalid] [tinyint] NOT NULL CONSTRAINT [DF_tmptreatment_isvalid]  DEFAULT ((0)),
	[userid] [int] NOT NULL,
	[isquantified] [int] NOT NULL CONSTRAINT [DF_tmptreatment_isquantified]  DEFAULT ((0)),
	[measurementunits] [nvarchar](50) NULL,
	[choicesDescription] [nvarchar](2000) NULL,
 CONSTRAINT [PK_tmptreatment] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[patienttreatment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[patienttreatment](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[prid] [int] NOT NULL,
	[treatmentid] [int] NOT NULL,
	[datavalue] [float] NOT NULL,
	[state] [int] NOT NULL,
	[startdate] [datetime] NOT NULL,
	[enddate] [datetime] NULL,
	[updatedate] [datetime] NOT NULL,
	[usepurpose] [int] NOT NULL,
	[stopreason] [int] NOT NULL,
	[unit] [nvarchar](50) NULL,
	[frequency] [nvarchar](50) NULL,
	[privacy] [int] NOT NULL CONSTRAINT [DF_patienttreatment_privacy]  DEFAULT ((0)),
 CONSTRAINT [PK_patienttreatment_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[diseasetreatment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[diseasetreatment](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[diseaseid] [int] NOT NULL,
	[treatmentid] [int] NOT NULL,
	[type] [int] NOT NULL CONSTRAINT [DF_diseasetreatment_type]  DEFAULT ((0)),
 CONSTRAINT [PK_diseasetreatment_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[treatmentevaluation]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[treatmentevaluation](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[prid] [int] NOT NULL,
	[treatmentid] [int] NOT NULL,
	[evaluation] [int] NOT NULL CONSTRAINT [DF_treatmentevaluation_evaluation]  DEFAULT ((0)),
 CONSTRAINT [PK_treatmentevaluation_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[patientrecord]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[patientrecord](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[patientid] [int] NOT NULL,
	[diseaseid] [int] NOT NULL,
	[recorddate] [datetime] NOT NULL,
	[updatedate] [datetime] NOT NULL,
	[remark] [nvarchar](max) COLLATE Chinese_PRC_CI_AS NULL,
	[startdate] [datetime] NOT NULL,
	[enddate] [datetime] NULL,
	[ConfirmDate] [datetime] NOT NULL,
	[ConfirmHospital] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
	[UpdateTime] [int] NOT NULL CONSTRAINT [DF_patientrecord_UpdateTime]  DEFAULT ((0)),
	CONSTRAINT [PK_patientrecord_id] PRIMARY KEY CLUSTERED 
	(
		[id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[diseaselabcheck]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[diseaselabcheck](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[diseaseid] [int] NOT NULL,
	[labcheckid] [int] NOT NULL,
	[type] [int] NOT NULL,
	[ChartIndex] [int] NOT NULL,
	[AxisIndex] [int] NOT NULL,
 CONSTRAINT [PK_diseaselabcheck] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[diseasesymptom]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[diseasesymptom](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[diseaseid] [int] NOT NULL,
	[symptomid] [int] NOT NULL,
	[type] [int] NOT NULL CONSTRAINT [DF_diseasesymptom_type]  DEFAULT ((0)),
 CONSTRAINT [PK_diseasesymptom_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[patientcheck]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[patientcheck](
	[id] [int] NOT NULL,
	[prid] [int] NOT NULL,
	[checkinfo] [nvarchar](500) NOT NULL,
	[recorddate] [datetime] NOT NULL,
	[updatedate] [datetime] NOT NULL,
	[remark] [nvarchar](2000) NULL,
 CONSTRAINT [PK_patientCheck] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[patientsymptom]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[patientsymptom](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[prid] [int] NOT NULL,
	[symptominfo] [nvarchar](2000) NOT NULL,
	[recorddate] [datetime] NOT NULL,
	[updatedate] [datetime] NOT NULL,
	[remark] [nvarchar](max) NULL,
 CONSTRAINT [PK_patientsymptom_id] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientSurvey]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientSurvey](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[RecordDate] [datetime] NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
	[SurveyType] [int] NOT NULL,
 CONSTRAINT [PK_PatientSurvey] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientCurrentSymptom]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientCurrentSymptom](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[SymptomId] [int] NOT NULL,
	[DegreeValue] [int] NOT NULL,
	[SymptomHistoryId] [int] NOT NULL,
 CONSTRAINT [PK_PatientCurrentSymptom] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientSymptomHistory]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientSymptomHistory](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[SymptomId] [int] NOT NULL,
	[SurveyId] [int] NOT NULL,
	[DegreeValue] [int] NOT NULL,
	[RecordDate] [datetime] NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
	[Remark] [nvarchar](2000) COLLATE Chinese_PRC_CI_AS NULL,
	[Type] [int] NULL CONSTRAINT [DF_PatientSymptomHistory_Type]  DEFAULT ((0)),
 CONSTRAINT [PK_PatientSymptomHistory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientCurrentIndicator]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientCurrentIndicator](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[IndicatorId] [int] NOT NULL,
	[DataValue] [float] NOT NULL CONSTRAINT [DF_PatientCurrentIndicator_DataValue]  DEFAULT ((0)),
	[IndicatorHistoryId] [int] NOT NULL,
 CONSTRAINT [PK_PatientCurrentIndicator] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientIndicatorHistory]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientIndicatorHistory](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[IndicatorId] [int] NOT NULL,
	[SurveyId] [int] NOT NULL,
	[DataValue] [float] NOT NULL,
	[RecordDate] [datetime] NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
	[Remark] [nvarchar](2000) COLLATE Chinese_PRC_CI_AS NULL,
 CONSTRAINT [PK_PatientIndicatorHistory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientCurrentWeight]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientCurrentWeight](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[DataValue] [float] NOT NULL,
	[WeightHistoryId] [int] NOT NULL,
 CONSTRAINT [PK_PatientCurrentWeight] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientWeightHistory]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientWeightHistory](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[DataValue] [float] NOT NULL,
	[RecordDate] [datetime] NOT NULL,
	[UpdateDate] [datetime] NOT NULL,
 CONSTRAINT [PK_PatientWeightHistory] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientCurrentTreatment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientCurrentTreatment](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[TreatmentId] [int] NOT NULL,
	[IsUsing] [int] NOT NULL,
	[DataValue] [float] NOT NULL,
	[TreatmentHistoryId] [int] NOT NULL,
	[UsedTotalDay] [int] NOT NULL CONSTRAINT [DF_PatientCurrentTreatment_UsedTotalDay]  DEFAULT ((0)),
	CONSTRAINT [PK_PatientCurrentTreatment] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO


SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PatientTreatmentHistory]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[PatientTreatmentHistory](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[PRId] [int] NOT NULL,
	[TreatmentId] [int] NOT NULL,
	[DataValue] [float] NOT NULL,
	[Frequency] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
	[State] [int] NOT NULL,
	[StartDate] [datetime] NOT NULL,
	[EndDate] [datetime] NOT NULL,
	[StopReason] [int] NOT NULL CONSTRAINT [DF_PatientTreatmentHistory_StopReason]  DEFAULT ((0)),
	[UsePurPose] [int] NOT NULL CONSTRAINT [DF_PatientTreatmentHistory_UsePurPose]  DEFAULT ((0)),
	[UpdateDate] [datetime] NOT NULL,
	[Privacy] [int] NOT NULL CONSTRAINT [DF_PatientTreatmentHistory_Privacy]  DEFAULT ((0)),
	CONSTRAINT [PK_PatientTreatmentHistory] PRIMARY KEY CLUSTERED 
	(
		[Id] ASC
	)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_textinfo_textinfotype]') AND parent_object_id = OBJECT_ID(N'[dbo].[textinfo]'))
ALTER TABLE [dbo].[textinfo]  WITH CHECK ADD  CONSTRAINT [FK_textinfo_textinfotype] FOREIGN KEY([typeid])
REFERENCES [dbo].[textinfotype] ([id])
GO
ALTER TABLE [dbo].[textinfo] CHECK CONSTRAINT [FK_textinfo_textinfotype]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tmpdisease_diseasetype]') AND parent_object_id = OBJECT_ID(N'[dbo].[tmpdisease]'))
ALTER TABLE [dbo].[tmpdisease]  WITH CHECK ADD  CONSTRAINT [FK_tmpdisease_diseasetype] FOREIGN KEY([diseasetypeid])
REFERENCES [dbo].[diseasetype] ([id])
GO
ALTER TABLE [dbo].[tmpdisease] CHECK CONSTRAINT [FK_tmpdisease_diseasetype]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tmpdisease_userinfo]') AND parent_object_id = OBJECT_ID(N'[dbo].[tmpdisease]'))
ALTER TABLE [dbo].[tmpdisease]  WITH CHECK ADD  CONSTRAINT [FK_tmpdisease_userinfo] FOREIGN KEY([userid])
REFERENCES [dbo].[userinfo] ([id])
GO
ALTER TABLE [dbo].[tmpdisease] CHECK CONSTRAINT [FK_tmpdisease_userinfo]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_disease_diseasetype]') AND parent_object_id = OBJECT_ID(N'[dbo].[disease]'))
ALTER TABLE [dbo].[disease]  WITH CHECK ADD  CONSTRAINT [FK_disease_diseasetype] FOREIGN KEY([diseasetypeid])
REFERENCES [dbo].[diseasetype] ([id])
GO
ALTER TABLE [dbo].[disease] CHECK CONSTRAINT [FK_disease_diseasetype]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tmpsymptom_symptomtype]') AND parent_object_id = OBJECT_ID(N'[dbo].[tmpsymptom]'))
ALTER TABLE [dbo].[tmpsymptom]  WITH CHECK ADD  CONSTRAINT [FK_tmpsymptom_symptomtype] FOREIGN KEY([symptomtypeid])
REFERENCES [dbo].[symptomtype] ([id])
GO
ALTER TABLE [dbo].[tmpsymptom] CHECK CONSTRAINT [FK_tmpsymptom_symptomtype]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_symptom_symptomtype]') AND parent_object_id = OBJECT_ID(N'[dbo].[symptom]'))
ALTER TABLE [dbo].[symptom]  WITH CHECK ADD  CONSTRAINT [FK_symptom_symptomtype] FOREIGN KEY([symptomtypeid])
REFERENCES [dbo].[symptomtype] ([id])
GO
ALTER TABLE [dbo].[symptom] CHECK CONSTRAINT [FK_symptom_symptomtype]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_treatment_treatmenttype]') AND parent_object_id = OBJECT_ID(N'[dbo].[treatment]'))
ALTER TABLE [dbo].[treatment]  WITH CHECK ADD  CONSTRAINT [FK_treatment_treatmenttype] FOREIGN KEY([treatmenttypeid])
REFERENCES [dbo].[treatmenttype] ([id])
GO
ALTER TABLE [dbo].[treatment] CHECK CONSTRAINT [FK_treatment_treatmenttype]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_tmptreatment_treatmenttype]') AND parent_object_id = OBJECT_ID(N'[dbo].[tmptreatment]'))
ALTER TABLE [dbo].[tmptreatment]  WITH CHECK ADD  CONSTRAINT [FK_tmptreatment_treatmenttype] FOREIGN KEY([treatmenttypeid])
REFERENCES [dbo].[treatmenttype] ([id])
GO
ALTER TABLE [dbo].[tmptreatment] CHECK CONSTRAINT [FK_tmptreatment_treatmenttype]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_patienttreatment_patientrecord]') AND parent_object_id = OBJECT_ID(N'[dbo].[patienttreatment]'))
ALTER TABLE [dbo].[patienttreatment]  WITH CHECK ADD  CONSTRAINT [FK_patienttreatment_patientrecord] FOREIGN KEY([prid])
REFERENCES [dbo].[patientrecord] ([id])
GO
ALTER TABLE [dbo].[patienttreatment] CHECK CONSTRAINT [FK_patienttreatment_patientrecord]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_patienttreatment_treatment]') AND parent_object_id = OBJECT_ID(N'[dbo].[patienttreatment]'))
ALTER TABLE [dbo].[patienttreatment]  WITH CHECK ADD  CONSTRAINT [FK_patienttreatment_treatment] FOREIGN KEY([treatmentid])
REFERENCES [dbo].[treatment] ([id])
GO
ALTER TABLE [dbo].[patienttreatment] CHECK CONSTRAINT [FK_patienttreatment_treatment]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_diseasetreatment_disease]') AND parent_object_id = OBJECT_ID(N'[dbo].[diseasetreatment]'))
ALTER TABLE [dbo].[diseasetreatment]  WITH CHECK ADD  CONSTRAINT [FK_diseasetreatment_disease] FOREIGN KEY([diseaseid])
REFERENCES [dbo].[disease] ([id])
GO
ALTER TABLE [dbo].[diseasetreatment] CHECK CONSTRAINT [FK_diseasetreatment_disease]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_diseasetreatment_treatment]') AND parent_object_id = OBJECT_ID(N'[dbo].[diseasetreatment]'))
ALTER TABLE [dbo].[diseasetreatment]  WITH CHECK ADD  CONSTRAINT [FK_diseasetreatment_treatment] FOREIGN KEY([treatmentid])
REFERENCES [dbo].[treatment] ([id])
GO
ALTER TABLE [dbo].[diseasetreatment] CHECK CONSTRAINT [FK_diseasetreatment_treatment]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_treatmentevaluation_patientrecord]') AND parent_object_id = OBJECT_ID(N'[dbo].[treatmentevaluation]'))
ALTER TABLE [dbo].[treatmentevaluation]  WITH CHECK ADD  CONSTRAINT [FK_treatmentevaluation_patientrecord] FOREIGN KEY([prid])
REFERENCES [dbo].[patientrecord] ([id])
GO
ALTER TABLE [dbo].[treatmentevaluation] CHECK CONSTRAINT [FK_treatmentevaluation_patientrecord]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_treatmentevaluation_treatment]') AND parent_object_id = OBJECT_ID(N'[dbo].[treatmentevaluation]'))
ALTER TABLE [dbo].[treatmentevaluation]  WITH CHECK ADD  CONSTRAINT [FK_treatmentevaluation_treatment] FOREIGN KEY([treatmentid])
REFERENCES [dbo].[treatment] ([id])
GO
ALTER TABLE [dbo].[treatmentevaluation] CHECK CONSTRAINT [FK_treatmentevaluation_treatment]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_patientrecord_disease]') AND parent_object_id = OBJECT_ID(N'[dbo].[patientrecord]'))
ALTER TABLE [dbo].[patientrecord]  WITH CHECK ADD  CONSTRAINT [FK_patientrecord_disease] FOREIGN KEY([diseaseid])
REFERENCES [dbo].[disease] ([id])
GO
ALTER TABLE [dbo].[patientrecord] CHECK CONSTRAINT [FK_patientrecord_disease]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_patientrecord_userinfo]') AND parent_object_id = OBJECT_ID(N'[dbo].[patientrecord]'))
ALTER TABLE [dbo].[patientrecord]  WITH CHECK ADD  CONSTRAINT [FK_patientrecord_userinfo] FOREIGN KEY([patientid])
REFERENCES [dbo].[userinfo] ([id])
GO
ALTER TABLE [dbo].[patientrecord] CHECK CONSTRAINT [FK_patientrecord_userinfo]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_diseaselabcheck_disease]') AND parent_object_id = OBJECT_ID(N'[dbo].[diseaselabcheck]'))
ALTER TABLE [dbo].[diseaselabcheck]  WITH CHECK ADD  CONSTRAINT [FK_diseaselabcheck_disease] FOREIGN KEY([diseaseid])
REFERENCES [dbo].[disease] ([id])
GO
ALTER TABLE [dbo].[diseaselabcheck] CHECK CONSTRAINT [FK_diseaselabcheck_disease]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_diseaselabcheck_labcheck]') AND parent_object_id = OBJECT_ID(N'[dbo].[diseaselabcheck]'))
ALTER TABLE [dbo].[diseaselabcheck]  WITH CHECK ADD  CONSTRAINT [FK_diseaselabcheck_labcheck] FOREIGN KEY([labcheckid])
REFERENCES [dbo].[labcheck] ([id])
GO
ALTER TABLE [dbo].[diseaselabcheck] CHECK CONSTRAINT [FK_diseaselabcheck_labcheck]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_diseasesymptom_disease]') AND parent_object_id = OBJECT_ID(N'[dbo].[diseasesymptom]'))
ALTER TABLE [dbo].[diseasesymptom]  WITH CHECK ADD  CONSTRAINT [FK_diseasesymptom_disease] FOREIGN KEY([diseaseid])
REFERENCES [dbo].[disease] ([id])
GO
ALTER TABLE [dbo].[diseasesymptom] CHECK CONSTRAINT [FK_diseasesymptom_disease]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_diseasesymptom_symptom]') AND parent_object_id = OBJECT_ID(N'[dbo].[diseasesymptom]'))
ALTER TABLE [dbo].[diseasesymptom]  WITH CHECK ADD  CONSTRAINT [FK_diseasesymptom_symptom] FOREIGN KEY([symptomid])
REFERENCES [dbo].[symptom] ([id])
GO
ALTER TABLE [dbo].[diseasesymptom] CHECK CONSTRAINT [FK_diseasesymptom_symptom]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_patientCheck_patientrecord]') AND parent_object_id = OBJECT_ID(N'[dbo].[patientcheck]'))
ALTER TABLE [dbo].[patientcheck]  WITH CHECK ADD  CONSTRAINT [FK_patientCheck_patientrecord] FOREIGN KEY([prid])
REFERENCES [dbo].[patientrecord] ([id])
GO
ALTER TABLE [dbo].[patientcheck] CHECK CONSTRAINT [FK_patientCheck_patientrecord]
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_patientsymptom_patientrecord]') AND parent_object_id = OBJECT_ID(N'[dbo].[patientsymptom]'))
ALTER TABLE [dbo].[patientsymptom]  WITH CHECK ADD  CONSTRAINT [FK_patientsymptom_patientrecord] FOREIGN KEY([prid])
REFERENCES [dbo].[patientrecord] ([id])
GO
ALTER TABLE [dbo].[patientsymptom] CHECK CONSTRAINT [FK_patientsymptom_patientrecord]
